import { createStore } from 'vuex'
import axios from 'axios'
export default createStore({
  state: {
    // 推荐数据
    remm: [],
    // 用户数据
    user: {
      isLogin: localStorage.getItem('token')? true: false,
      username: localStorage.getItem('token')
    }
  },
  mutations: {
    SET_REMM(state, payload) {
      state.remm = payload
    },
    SET_USER(state, payload) {
      state.user = { ...state.user, ...payload }
      console.log(state.user);
    },
    QUIT(state) {
      console.log(123);
      localStorage.removeItem('token')
      state.user = { isLogin: false, username: '' }
    }
  },
  getters: {
    // 详情数据
    postDetail(state) {
      return function (id) {
        return state.remm.find(item => item.id === id)
      }
    }
  },
  actions: {
    async GET_REMM({ commit }) {
      const resp = await axios.get("/remm");
      commit('SET_REMM', resp.data.data)
    }
  },
  modules: {
  }
})
